package com.hex.ds.hdtp.core.inf.script.common.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hex.ds.hdtp.core.inf.script.analyze.po.ScriptAnalyzeTransferPo;
import com.hex.ds.hdtp.core.inf.script.common.mapper.IScriptTableConsanguinityMapper;
import com.hex.ds.hdtp.core.inf.script.common.po.ScriptTableConsanguinityPo;
import com.hex.ds.hdtp.core.inf.script.common.repository.IScriptTableConsanguinityRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.inf.script.test.repository.impl
 * @ClassName ScriptTableConsanguinityRepository
 * @Description: 脚本表血缘-数据接口实现
 * @Author: wz.li
 * @Date 2023/8/3 11:07
 * @Version v2.0.2
 **/
@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ScriptTableConsanguinityRepository implements IScriptTableConsanguinityRepository {

    private final IScriptTableConsanguinityMapper scriptTestConsanguinityMapper;

    private static final String DATA_FROM = "data_from";

    private static final String LIST_PK_ID = "script_list_pk_id";

    /*
     * @Method: queryList <br>
     * @Param: [scriptListPkId, dataFrom] <br>
     * @Return: java.util.List<com.hex.ds.hdtp.core.inf.script.common.po.ScriptTableConsanguinityPo> <br>
     * @Description：根据脚本清单主键和数据来源查询对应的表血缘<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/3 11:42 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public List<ScriptTableConsanguinityPo> queryList(String scriptListPkId, String dataFrom) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(LIST_PK_ID, scriptListPkId);
        queryWrapper.eq(DATA_FROM, dataFrom);
        return scriptTestConsanguinityMapper.selectList(queryWrapper);
    }

    @Override
    public List<ScriptTableConsanguinityPo> queryListByTaskId(String taskPkId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("task_pk_id", taskPkId);
        return scriptTestConsanguinityMapper.selectList(queryWrapper);
    }

    /*
     * @Method: removeByScriptListPkId <br>
     * @Param: [scriptListPkId, dataFrom] <br>
     * @Return: int <br>
     * @Description：根据脚本清单主键和数据来源删除对应的表血缘<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/4 11:58 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public int removeByScriptListPkId(String scriptListPkId, String dataFrom) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(LIST_PK_ID, scriptListPkId);
        queryWrapper.eq(DATA_FROM, dataFrom);
        return scriptTestConsanguinityMapper.delete(queryWrapper);
    }

    /*
     * @Method: queryById <br>
     * @Param: [pkId] <br>
     * @Return: com.hex.ds.hdtp.core.inf.script.test.po.ScriptTestConsanguinityPo <br>
     * @Description：根据主键查询<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 15:02 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public ScriptTableConsanguinityPo queryById(String pkId) {
        return scriptTestConsanguinityMapper.selectById(pkId);
    }

    /*
     * @Method: add <br>
     * @Param: [scriptTestConsanguinityPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：新增<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 15:02 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer add(ScriptTableConsanguinityPo scriptTableConsanguinityPo) {
        return scriptTestConsanguinityMapper.insert(scriptTableConsanguinityPo);
    }

    /*
     * @Method: modifyById <br>
     * @Param: [scriptTestConsanguinityPo] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键更新<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 15:02 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer modifyById(ScriptTableConsanguinityPo scriptTableConsanguinityPo) {
        return scriptTestConsanguinityMapper.updateById(scriptTableConsanguinityPo);
    }

    /*
     * @Method: removeById <br>
     * @Param: [pkId] <br>
     * @Return: java.lang.Integer <br>
     * @Description：根据主键删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/1 15:02 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public Integer removeById(String pkId) {
        return scriptTestConsanguinityMapper.deleteById(pkId);
    }

    /*
     * @Method: removeByTableName <br>
     * @Param: [scriptTableConsanguinityPo] <br>
     * @Return: int <br>
     * @Description：根据表名删除<br>
     * @Author： wz.li<br>
     * @Date： 2023/8/8 11:44 <br>
     * @Version： V2.0.2<br>
     */
    @Override
    public int removeByTableName(ScriptTableConsanguinityPo scriptTableConsanguinityPo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("task_pk_id", scriptTableConsanguinityPo.getTaskPkId());
        queryWrapper.eq(LIST_PK_ID, scriptTableConsanguinityPo.getScriptListPkId());
        queryWrapper.eq("script_name", scriptTableConsanguinityPo.getScriptName());
        queryWrapper.eq("table_name", scriptTableConsanguinityPo.getTableName());
        queryWrapper.eq("table_type", scriptTableConsanguinityPo.getTableType());
        queryWrapper.eq(DATA_FROM, scriptTableConsanguinityPo.getDataFrom());
        return scriptTestConsanguinityMapper.delete(queryWrapper);
    }

}
